home *** CD-ROM | disk | FTP | other *** search
/ SVM Mac 58 / CD-ROM N°58.iso / navigateurs / Netscape Folder / chrome / messengercompose / content / default / addressAutoComplete.js next >
Encoding:
JavaScript  |  2000-04-19  |  2.7 KB  |  93 lines  |  [TEXT/MOSS]

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  * Jean-Francois Ducarroz <ducarroz@netscape.com>
  22.  * Seth Spitzer <sspitzer@netscape.com>
  23.  * Alec Flett <alecf@netscape.com>
  24.  */
  25.  
  26. // get the current identity from the UI
  27. var identityElement;
  28.  
  29. var accountManager = Components.classes["component://netscape/messenger/account-manager"].getService(Components.interfaces.nsIMsgAccountManager);
  30.  
  31.     
  32. var AddressAutoCompleteListener = {
  33.     onAutoCompleteResult: function(aItem, aOriginalString, aMatch) {
  34.         dump("aItem = " + aItem + "\n");
  35.  
  36.         if ( aItem )
  37.         {
  38.             dump("value = " + aItem.value + "\n");
  39.             dump("aOriginalString = " + aOriginalString + "\n");
  40.             dump("aMatch = " + aMatch + "\n");
  41.  
  42.             aItem.value = aMatch;
  43.             aItem.lastValue = aMatch;
  44.         }
  45.     }
  46. };
  47.  
  48. function AutoCompleteAddress(inputElement)
  49. {
  50.     ///////////// (select_doc_id, doc_id)
  51.  
  52.     dump("inputElement = " + inputElement + "\n");
  53.  
  54.     //Do we really have to autocomplete?
  55.     if (inputElement.lastValue && inputElement.lastValue == inputElement.value)
  56.         return;
  57.  
  58.     var row = awGetRowByInputElement(inputElement);    
  59.  
  60.     var select = awGetPopupElement(row);
  61.     
  62.     dump("select = " + select + "\n");
  63.     dump("select.value = " + select.value + "\n");
  64.     
  65.     if (select.value == "") 
  66.         return;
  67.  
  68.     if (select.value == "addr_newsgroups") {
  69.         dump("don't autocomplete, it's a newsgroup");
  70.         return;
  71.     }
  72.     
  73.     var ac = Components.classes['component://netscape/messenger/autocomplete&type=addrbook'];
  74.     if (ac) {
  75.         ac = ac.getService();
  76.     }       
  77.     if (ac) {
  78.         ac = ac.QueryInterface(Components.interfaces.nsIAutoCompleteSession);
  79.     }
  80.  
  81.     if (!identityElement)
  82.         identityElement = document.getElementById("msgIdentity");
  83.  
  84.     var identity=null;
  85.     
  86.     if (identityElement) {
  87.         idKey = identityElement.value;
  88.         identity = accountManager.getIdentity(idKey);
  89.     }
  90.  
  91.     ac.autoComplete(identity, inputElement, inputElement.value, AddressAutoCompleteListener);
  92. }
  93.